<!DOCTYPE html>
<html>

<head>
  <title>A Shot of Quarkus with a Cassandra Chaser: Time for Faster Microservices</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/blog/quarkus-cassandra-extension-released/" />
  <meta property="og:title" content="A Shot of Quarkus with a Cassandra Chaser: Time for Faster Microservices" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/blog/quarkus-cassandra-extension-released/">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="post">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="active">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="post-page grid-wrapper">
  <div class="width-8-12 width-12-12-m doc-content">
    <div class="grid-wrapper">
      <div class="width-12-12">
        <p>
          <a href="/blog"><i class="fas fa-angle-left"></i> Back to all posts</a>
        </p>
      </div>
      <div class="width-12-12">
        <div class="post-date">
          July 09, 2020 
          
            <span class="tags"><a href="/blog/tag/extension">#extension</a><a href="/blog/tag/cassandra">#cassandra</a></span>
          
        </div>
        <h1 class="post-title">A Shot of Quarkus with a Cassandra Chaser: Time for Faster Microservices</h1>
        <div class="grid-wrapper">
          <div class="width-8-12 width-12-12-m byline-wrapper">
            
            
              <img class="headshot" src="https://www.gravatar.com/avatar/4d33b3e2469c5208da6708ad96634e64">
            
            <p class="byline">By Chris Splinter</p>
          </div>
          <div class="width-12-12">
              <div class="paragraph">
<p>With the new <a href="https://quarkus.io/guides/cassandra">Quarkus extension for Apache Cassandra</a>® released in Quarkus 1.6, all it takes is a few lines of code to connect to and access your data stored in Cassandra and you get all of the benefits of Quarkus (fast-startup, low resource utilization, reactive programming).</p>
</div>
<div class="paragraph">
<p>To enable the extension, add <code>cassandra-quarkus-client</code> to your application. You can do this by including the following dependency or by selecting Cassandra client in the <a href="https://code.quarkus.io/">project generator</a>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs"># the version at time of writing is 1.0.0-alpha3
&lt;dependency&gt;
  &lt;groupId&gt;com.datastax.oss.quarkus&lt;/groupId&gt;
  &lt;artifactId&gt;cassandra-quarkus-client&lt;/artifactId&gt;
  &lt;version&gt;${cassandra-quarkus.version}&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The most common database connection settings can be configured directly in an <code>application.properties</code> file on the classpath, see below for an example. All of the settings and features of the <a href="https://docs.datastax.com/en/developer/java-driver/latest">DataStax Java driver for Cassandra</a> are available to you and the <a href="https://docs.datastax.com/en/developer/java-driver/latest/manual/core/configuration/reference/">advanced driver settings</a> can be placed in an <code>application.conf</code> file on the classpath.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="properties" class="language-properties hljs"># Connecting to DataStax Astra astra.datastax.com
# if specified, contact-points and local-datacenter are not needed
quarkus.cassandra.cloud.secure-connect-bundle=/path/to/secure-connect-bundle.zip

# Connection details
quarkus.cassandra.contact-points=127.0.0.1:9042
quarkus.cassandra.local-datacenter=dc1
quarkus.cassandra.keyspace=&lt;your keyspace&gt;

# Authentication
quarkus.cassandra.auth.username=&lt;your username&gt;
quarkus.cassandra.auth.password=&lt;your password&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Once the database connection is configured, simply inject the <a href="https://www.javadoc.io/static/com.datastax.oss.quarkus/cassandra-quarkus-client/1.0.0-alpha1/com/datastax/oss/quarkus/runtime/api/session/QuarkusCqlSession.html"><code>QuarkusCqlSession</code></a> in your application to get started. For seamless integration with <a href="https://quarkus.io/guides/getting-started-reactive">reactive applications</a>, there is an <code>executeReactive</code> method on the <code>QuarkusCqlSession</code> that exposes Mutiny-compatible reactive execution methods and direct retrieval of Mutiny types.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@ApplicationScoped
public class ProductService {

  @Inject
  private QuarkusCqlSession session;

  public Multi&lt;Product&gt; getAllProducts() {
    Multi&lt;ReactiveRow&gt; products = session.executeReactive("SELECT * from products");
    return products.on().item().apply(Product::new);
  }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Mutiny types are also available when using the Cassandra Java driver&#8217;s <a href="https://docs.datastax.com/en/developer/java-driver/4.7/manual/mapper/">object mapper</a>. With the Quarkus Cassandra extension, you can easily define your mapped entities and DAOs and then inject your DAOs in your reactive services in just a few lines of code!</p>
</div>
<div class="paragraph">
<p>For example, suppose that you have a <code>Product</code> entity, a <code>ProductDao</code> and a <code>ProductMapper</code> with standard CRUD operations, you can expose your DAO as an injectable bean:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class ProductDaoProducer {

  private final ProductDao dao;

  @Inject
  public ProductDaoProducer(QuarkusCqlSession cqlSession) {
    ProductMapper mapper = new ProductMapperBuilder(cqlSession).build();
    this.dao = mapper.productDao();
  }

  @Produces @ApplicationScoped
  public ProductDao produceProductDao() { return dao; }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>… then inject it in a <code>ProductService</code> component, as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@ApplicationScoped
public class ProductService {

  @Inject
  private ProductDao dao;

  public Uni&lt;Product&gt; findProduct(String id) { return dao.findById(id); }

  public Multi&lt;Product&gt; getAllProducts() { return dao.findAll(); }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can retrieve this example and many others in <a href="https://github.com/datastax/cassandra-quarkus/blob/master/documentation/src/main/asciidoc/cassandraclient.adoc">the quickstart guide</a>, which includes how to use the Quarkus Cassandra extension in <a href="https://quarkus.io/guides/building-native-image">native mode</a>. For users that are looking to get up and running in minutes with Cassandra, try out the free-tier in <a href="https://astra.datastax.com/">DataStax Astra</a>.</p>
</div>
<div class="paragraph">
<p>We value your feedback so please don&#8217;t hesitate to open feature requests and bug reports in the <a href="https://github.com/datastax/cassandra-quarkus">extensions GitHub repository</a>, ask questions at <a href="https://community.datastax.com/">community.datastax.com</a>, or join the <a href="https://cassandra.apache.org/community/">Cassandra</a> and <a href="https://quarkus.io/community/">Quarkus</a> communities.</p>
</div>
<div class="paragraph">
<p>Happy subatomic coding!</p>
</div>
              
          </div>
          <div class="width-12-12"><div class="share-page">
  <a class="share-linkedin" href="https://www.linkedin.com/shareArticle?mini=true&url=https://quarkus.io/blog/quarkus-cassandra-extension-released/&title=A Shot of Quarkus with a Cassandra Chaser: Time for Faster Microservices" rel="nofollow" target="_blank" title="Share on LinkedIn">
    <img src="/assets/images/share-page/icons_social-linkedin.png"/>
  </a>
  <a class="share-twitter" href="https://twitter.com/intent/tweet?text=A Shot of Quarkus with a Cassandra Chaser: Time for Faster Microservices&url=https://quarkus.io/blog/quarkus-cassandra-extension-released/&via=quarkusio&related=quarkusio" rel="nofollow" target="_blank" title="Share on Twitter">
    <img src="/assets/images/share-page/icons_social-twitter.png"/>
  </a>
  <a class="share-facebook" href="https://facebook.com/sharer.php?u=https://quarkus.io/blog/quarkus-cassandra-extension-released/" rel="nofollow" target="_blank" title="Share on Facebook">
    <img src="/assets/images/share-page/icons_social-facebook.png"/>
  </a>
  <a class="share-reddit" href="http://www.reddit.com/submit?url=https://quarkus.io/blog/quarkus-cassandra-extension-released/" onclick="window.open(this.href, 'pop-up', 'left=20,top=20,width=900,height=500,toolbar=1,resizable=0'); return false;" title="Share on Reddit" >
    <img src="/assets/images/share-page/icons_social-reddit.png"/>
  </a>
  <a class="share-email" href="mailto:?subject=A Shot of Quarkus with a Cassandra Chaser: Time for Faster Microservices&amp;body=A Shot of Quarkus with a Cassandra Chaser: Time for Faster Microservices https://quarkus.io/blog/quarkus-cassandra-extension-released/" title="Share via Email" >
    <img src="/assets/images/share-page/icons_social-email.png"/>
  </a>
</div>
</div>
        </div>
      </div>
    </div>
  </div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
